﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using Xamarin.Forms;

namespace MasterDetailTemplate.Converters {
    /// <summary>
    /// 倒数日转换器
    /// </summary>
    public class CountDayConverter : IValueConverter {
        public object Convert(object value, Type targetType, object parameter,
            CultureInfo culture) {
            DateTime Date = (DateTime) value;
            DateTime Now = DateTime.Now;
            if (Date.ToString("MM/dd/yyyy").Equals(Now.ToString("MM/dd/yyyy")))
                return "今天";

            TimeSpan sqan = Date.Subtract(Now);
            String day = "";
            if (sqan.Days < 0) {
                day = "过了" + Math.Abs(sqan.Days) + "天";
            } else {
                day = (sqan.Days + 1) + "天后";
            }

            return day;
        }

        public object ConvertBack(object value, Type targetType,
            object parameter, CultureInfo culture) {
            throw new NotImplementedException();
        }
    }
}